<template>
  <div>
    <el-dialog width="400px" v-model="dialogFormVisible" :draggable="true" :show-close="false" @close="dialogClose">
      <div class="qrcode-box">
        <qrcode-vue :value="realForm.qrUrl" size="200" level="L" />
        <p>请使用支付宝APP扫一扫认证</p>
      </div>
      <div v-show="signState == 3" class="">

      </div>
      <div v-show="signState == 4" class="">

      </div>
    </el-dialog>
  </div>
</template>

<script>
import { reactive, ref, toRefs } from 'vue'
import api from '../api'
import { warningDeal } from '@/utils/utils'
import QrcodeVue from 'qrcode.vue'
export default {
  components: {
    QrcodeVue
  },
  setup(props, context) {
    const state = reactive({
      myTimer: null,
      signState: null,
      realForm: {},
      dialogFormVisible: false,
    })

    function dialogShow(data) {
      state.realForm = data
      state.dialogFormVisible = true
      getRealResults()
    }

    //查询实名结果
    function getRealResults() {
      clearInterval(state.myTimer)
      const obj = {
        orderNo: state.realForm.orderNo
      }
      state.myTimer = setInterval(() => {
        api.livingResult(obj).then(res => {
          if (res.code == '200') {
            if (res.data.signState != 1) {
              clearInterval(state.myTimer)
              context.emit('realEnd', { signState: res.data.signState, orderNo: state.realForm.orderNo })
              state.dialogFormVisible = false
            }
            state.signState = res.data.signState
          } else {
            warningDeal(res.msg)
          }
        }).catch(err => {
          console.log(err)
        })
      }, 3000);
    }

    function dialogClose() {

    }

    return {
      ...toRefs(state),
      dialogShow,
      dialogClose,
    }
  }
}
</script>

<style lang="scss" scoped>
.qrcode-box {
  width: 100%;
  text-align: center;
  > p {
    font-size: 16px;
    margin-top: 20px;
  }
}
</style>